package com.system.insurance.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.system.common.result.Result;
import com.system.insurance.entity.*;
import com.system.insurance.service.ReleaseRecordService;
import com.system.insurance.service.ReleaseersService;
import com.system.insurance.utils.AuthContextUtil;
import com.system.insurance.utils.UniqueValueUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 报价段增加发布次数 前端控制器
 * </p>
 *
 * @author WS
 * @since 2024-05-21
 */
@RestController
@RequestMapping("/insurance/releaseers")
public class ReleaseersController {


    @Autowired
    private ReleaseersService releaseersService;


    @Autowired
    private ReleaseRecordService releaseRecordService;


    @ApiOperation(value = "查看增加次数列表")
    @GetMapping("selectNum")
    public Result selectNum(){
        List<Releaseers> list = releaseersService.list();

        return Result.ok(list);
    }


//    @ApiOperation(value = "报价方: 增加发布次数")
//    @PostMapping("/saveIssueNum")
//    public Result saveIssueNum(@RequestBody Releaseers quotationForm,HttpServletRequest request, HttpServletResponse response){
//
//        String s = AuthContextUtil.get();
////TODO 支付功能
//
//                BigDecimal price = quotationForm.getPrice();
//                ReleaseRecord offerRecord = new ReleaseRecord();
//                offerRecord.setAppletUserId(Integer.valueOf(s));
//                offerRecord.setOrderNumber(UniqueValueUtils.createByDateTime());
//                offerRecord.setNumber(quotationForm.getNum());
//                offerRecord.setPrice(price);
//
//                boolean isSuccess = releaseRecordService.save(offerRecord);
//
//                if (isSuccess) {
//                    // 根据刚生成的订单号，查询订单信息获取订单id
////            QueryWrapper<EvaluationRecord> queryWrapper = new QueryWrapper<>();
////            queryWrapper.eq("order_id", reward1.getOrderId());
//                    LambdaQueryWrapper<ReleaseRecord> queryWrapper = new LambdaQueryWrapper<>();
//                    queryWrapper.eq(ReleaseRecord::getOrderNumber, offerRecord.getOrderNumber());
//
//                    ReleaseRecord orderDetail = releaseRecordService.getOne(queryWrapper);
////                    Integer id = orderDetail.getBjdid();
////                    log.info("CarteOrdersPay" + id);
//                    Object ordersPay = releaseRecordService.CarteOrdersPay(request, response,orderDetail);
//                    if (ordersPay != null) {
////                    return Result.ok(ordersPay);
////          LambdaQueryWrapper<QuotationForm> wrapper = new LambdaQueryWrapper<>();
////            wrapper.eq(QuotationForm::getId, quotationForm.getId());
////            QuotationForm list1 = quotationFormService.getOne(wrapper);
//
//                        return Result.ok(ordersPay);
//                    } else {
//                        return Result.fail("支付失败！");
//                    }
//                } else {
//                    return Result.fail("订单创建失败！");
//        }
//    }



//    /**
//     * 微信通知回调地址
//     *
//     * @param request
//     * @param response
//     * @return
//     */
//    @PostMapping("/wxBuy")
//    public String wxBuy(HttpServletRequest request, HttpServletResponse response) {
//        System.out.println("===========微信回调============");
//        Object o = releaseRecordService.wxBuy(request, response);
//        if (o != null) {
//            return "success";
//        }
//        return "failed";
//
//    }
//
//
//    /**
//     * 提供给前端查询支付订单状态的接口
//     *
//     * @param orderId
//     * @return
//     */
//    @GetMapping("/queryOderStatus")
//    public Result queryOderStatus(@RequestParam String orderId) {
//        ReleaseRecord orderDetail = releaseRecordService.getOrders(orderId);
//        if (orderDetail != null) {
//            return Result.ok(orderDetail);
//        }
//        return Result.fail("sorry,没有查询到该订单");
//    }
//
//    /**
//     * 查询订单的一个接口回调
//     *# orderNo
//     * @param orderNumber
//     *
//     * @return
//     * @throws Exception
//     */
//    @GetMapping("/query")
//    public Result queryOrder(@RequestParam String orderNumber) throws Exception {
//        Object queryOrder = releaseRecordService.queryOderStatus(orderNumber);
//        if (queryOrder != null) {
//            return Result.ok(queryOrder);
//        }
//        return Result.fail("failed");
//    }

}

